//公用样式 
require('../../assets/css/index.less')
require('../../assets/fonts/iconfont.css') //字体样式

// 当前页面样式
require('./course-description.less')

//工具函数 utils
const dom = require('../../utils/dom');
const local = require('../../utils/local');
//引入axios封装的文件
let https = require('../../utils/https.js');


dom.isLogin()

dom.ready(function () {
    let video = document.querySelector('video');
    //DOM加载事件
    //DOM加载事件
    //后退
    dom.getEle('#goBack').addEventListener('click', function () {
        history.go(-1)
    });

    //点击视频预览按钮播放视频
    dom.addEvent('#preview', function (res) {
        dom.getEle('.preview').style.display = 'none';
        video.style.display = 'block';
        // video.play();
         
    })


    //点击播放、暂停
    dom.getEle('.top').addEventListener('click', function () {
        console.log(111);
        if (video.paused) {
            video.play()
        } else {
            video.pause()
        }
    });


    //获取地址栏传过来的id
    // let id = location.search.split('=')[1];
    // let id = location.search.slice(4);
    let id = location.search.slice(location.search.indexOf('=') + 1);

    //获取当前详情信息
    let videData;

    function getInfo() {
        https.get('/api/train/courseDetail?id=' + id, function (res) {
            let {
                errno,
                data
            } = res;

            if (errno == 0) {
                console.log(data);
                //把视频相关的内容存到全局中
                videData = data.fragments;

                dom.getEle('video').src=https.BASE_URL + data.fragments[0].videoUrl
                dom.getEle('#name').innerHTML=data.name;
                dom.getEle('#calorie').innerHTML=data.calorie;
                dom.getEle('#time').innerHTML=data.time;
                dom.getEle('#peopleNum').innerHTML=data.peoplenum;
                dom.getEle('#desc').innerHTML=data.desc;
                dom.getEle('#frequency').innerHTML=data.frequency;
                dom.getEle('#instrument').innerHTML=data.instrument;
                dom.getEle('#imgUrl').innerHTML= https.BASE_URL + data.imgurl;

                local.set('vides', data.fragments)
            }
        })
    }
   
    getInfo()


    
    //点击开始训练跳转
    dom.addEvent('#startBtn', function (res) {
        //把数据存储到本地
        local.set('vides', videData)
        //跳转页面
        location.href = 'player.html'

    })

   





})